package com.yanqu.road.server;

import com.yanqu.road.entity.config.skin.SkinInfo;
import com.yanqu.road.entity.enums.eSkinType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public abstract class TempMgr {

	//活动id,修复代号,userId
	private static Map<Integer,Map<String, Map<Long,String>>> bugRecordMap;

	private static Logger logger = LogManager.getLogger(TempMgr.class.getName());

	public abstract boolean init() throws Exception;

	public boolean reload() throws Exception {
		return reloadConfig() && reloadData();
	}

	public abstract boolean reloadConfig() throws Exception;

	public abstract boolean reloadData() throws Exception;

	public abstract boolean stop();

	public boolean save() {
		return true;
	}

	public static Logger getLogger() {
		return logger;
	}

	public boolean isPatronsSkillRepeat(Map<Integer, SkinInfo> skinInfoMap) {
		Map<Integer, Map<Integer, Integer>> skillIdMap = new HashMap<>();
		for (SkinInfo skinInfo : skinInfoMap.values()) {
			if (skinInfo.getType() != eSkinType.Patrons.getValue()) {
				continue;
			}
			if(!skillIdMap.containsKey(skinInfo.getBelongRole())){
				skillIdMap.put(skinInfo.getBelongRole(), new HashMap<>());
			}
			for (Integer skillId : skinInfo.getSkinEffect()) {
				if (skillIdMap.get(skinInfo.getBelongRole()).containsKey(skillId)) {
					logger.error("门客皮肤技能重复！patronsId={},skinId={},skillId={}", skinInfo.getBelongRole(), skinInfo.getSkinId(), skillId);
					logger.error("门客皮肤技能重复！other,skinId={}", skillIdMap.get(skinInfo.getBelongRole()).get(skillId));
					return true;
				}

				skillIdMap.get(skinInfo.getBelongRole()).put(skillId, skinInfo.getSkinId());
			}
		}

		return false;
	}
}
